#ifndef TRANSACTION_TRANSACTIONLOG_H
#define TRANSACTION_TRANSACTIONLOG_H 1

#define TRANSACTION_MAX_CONCURRENT 40

#include <stdio.h>
#include <sys/types.h>

#include <common/macro/build.h>
#include <common/io.h>

typedef struct transaction_log_t {
	iohandle_t file;
	size_t maxitems;
} transaction_log_t;

API_LIBLOCAL transaction_log_t *transaction_log_open(const char *);
API_LIBLOCAL inline transaction_id_t transaction_log_replaces(transaction_log_t *, transaction_id_t);
API_LIBLOCAL void transaction_log_close(transaction_log_t *);
API_LIBLOCAL int transaction_log_get_current(transaction_log_t *, transaction_id_t *);
API_LIBLOCAL int transaction_log_set_current(transaction_log_t *, transaction_id_t);
API_LIBLOCAL int transaction_log_get_vacuum(transaction_log_t *, transaction_id_t *);
API_LIBLOCAL int transaction_log_set_vacuum(transaction_log_t *, transaction_id_t);
API_LIBLOCAL int transaction_log_flush(transaction_log_t *);

API_LIBLOCAL int transaction_log_write_phase(transaction_log_t *, transaction_id_t, transaction_phase_e);
API_LIBLOCAL int transaction_log_read_phase(transaction_log_t *, transaction_id_t, transaction_phase_e *);
API_LIBLOCAL transaction_phase_e *transaction_log_dump(transaction_log_t *, transaction_id_t *, transaction_id_t *);

API_LIBLOCAL int transaction_log_lock_item(transaction_log_t *, transaction_id_t);
API_LIBLOCAL int transaction_log_unlock_item(transaction_log_t *, transaction_id_t);
API_LIBLOCAL int transaction_log_checklock(transaction_log_t *, transaction_id_t);

API_LIBLOCAL int transaction_log_writelock_current(transaction_log_t *);
API_LIBLOCAL int transaction_log_readlock_current(transaction_log_t *);
API_LIBLOCAL int transaction_log_unlock_current(transaction_log_t *);

API_LIBLOCAL int transaction_log_writelock_vacuum(transaction_log_t *);
API_LIBLOCAL int transaction_log_readlock_vacuum(transaction_log_t *);
API_LIBLOCAL int transaction_log_unlock_vacuum(transaction_log_t *);


#endif
